﻿//var lockedAllowed = window.screen.mozLockOrientation("landscape");

define(['jquery', '../javascripts/i18next-1.5.10', 'lib/class', 'lib/underscore.min', 'lib/stacktrace', 'util'], function($) {
    
	
	var langCode = navigator.mozL10n.language.code;

	if (langCode.startsWith("de")) {
		langCode = "de-DE";
	} else if (langCode.startsWith("da")) {
		langCode = "da-DK";
	} else if (langCode.startsWith("en")) {
		langCode = "en-US";
	} else if (langCode.startsWith("es")) {
		langCode = "es-ES";
	} else if (langCode.startsWith("fi")) {
		langCode = "fr-FR";
	} else if (langCode.startsWith("it")) {
		langCode = "it-IT";
	} else if (langCode.startsWith("pt")) {
		langCode = "pt";
	}

	if (langCode == "da-DK" 
		|| langCode == "de-DE"
		|| langCode == "en-US"
		|| langCode == "es-ES"
		|| langCode == "fr-FR"
		|| langCode == "it-IT"
		|| langCode == "pt") {
		//Ok
	} else {
		langCode = "en-US";
	}

	//var langCode = "da-DK";

	//Load localized images by CSS
	var css = $("<link>");
	css.attr({
		rel:  "stylesheet",
		type: "text/css",
		href: "/css/lang/" + langCode + "/main.css"
	});
	$("head").append(css);
	
	
	//Should be getAsync:true for Windows Phone to work
	var option = { resGetPath: 'strings/' + langCode + '/__ns__.txt', debug: true , getAsync: true, keyseparator : '---',
		ns: { namespaces: ['resources'], defaultNs: 'resources'} , fallbackLng : 'en-US'
	};
	
	i18n.init(option, function (t) {
		$('body').i18n();

		window.gls = function (key) {
			return i18n.t(key);
		};
		//ready to play
		require(["main"]);
	});
	
});